<template>
	<view class="good-item">
		<!-- 左侧图片 -->
		<view class="good-item-left">
			<radio :checked="item.goods_state" color="#c00000" v-if="showRadio" @click="radioClick"></radio>
			<image :src="item.goods_big_logo || defaultpicture" class="good-pic"></image>
		</view>
		<!-- 右侧文字 -->
		<view class="good-item-right" >
			<view class="good-name">
				{{item.goods_name}}
			</view>
			<view class="good-info-box">
				<view class="good-price">￥{{item.goods_price | toFixed}}</view>
				<uni-number-box :min="1" :value="item.goods_count" v-if="showNumber" @change="numberChange"></uni-number-box>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name:"my-goods",
		data() {
			return {
				defaultpicture:'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'	
			};
		},
		props:{
			item:{
				type:Object,
				default:{}
			},
			showRadio:{
				type:Boolean,
				default:false
			},
			showNumber:{
				type:Boolean,
				default:false
			}
		},
		filters:{
			toFixed(num){
				return Number(num).toFixed(2)
			}
		},
		methods:{
			radioClick(){
				this.$emit('radio-change',{
					goods_id:this.item.goods_id,
					goods_state:!this.item.goods_state
				})
			},
			/* 监听购物车数量的事件 */
			numberChange(val){
				this.$emit('number-change',{
					goods_id:this.item.goods_id,
					goods_count:val-0
				})
			}
		}
	}
</script>

<style lang="scss">
	.good-item{
		display: flex;
		padding: 10px 5px;
		border: 1px solid #e2e1e4;
		.good-item-left{
			margin-right: 5px;
			display: flex;
			justify-content: space-between;
			align-items: center;
			.good-pic{ 
				width: 100px;
				height: 100px;
				display: block;
			}
		}
		.good-item-right{
			display: flex;
			flex: 1;
			flex-direction: column;
			justify-content: space-between;
			.good-name{
				font-size: 13px;
			}
			.good-info-box{
				display: flex;
				justify-content: space-between;
				align-items: center;
				.good-price{
					color: #a61b29;
					font-size: 16px;
				}
			}
		}
	}
</style>